package com.fuhao.demo.mvc.action;

import com.fuhao.demo.service.IDemoService;
import com.fuhao.mvcframework.annotation.FHAutowired;
import com.fuhao.mvcframework.annotation.FHController;
import com.fuhao.mvcframework.annotation.FHRequestMapping;
import com.fuhao.mvcframework.annotation.FHRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 2019/10/28.
 */
@FHController
@FHRequestMapping("/demo")
public class DemoAction {

    @FHAutowired
    private IDemoService demoService;

    @FHRequestMapping("/query")
    public void query(HttpServletRequest req, HttpServletResponse resp,
                      @FHRequestParam("name") String name){
        String result = demoService.get(name);
        try {
            resp.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @FHRequestMapping("/add")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @FHRequestParam("a") Integer a,@FHRequestParam("b") Integer b){
        try {
            resp.getWriter().write(a+"+"+b+"="+(a+b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @FHRequestMapping("/remove")
    public void remove(HttpServletRequest req, HttpServletResponse resp,
                       @FHRequestParam("id") Integer id){
    }
}
